#include "iUiList.h"

void iUiList::DrawItem(HDC hdcDst, int nIndex, RECT* prcItem, RECT *prcWin, RECT *prcUpdate)
{
	DrawItem_Background(hdcDst, prcItem, nIndex);
}

void iUiList::DrawItem_Background(HDC hdc, RECT* pRect,int index )
{
	BOOL bSelected = FALSE;
	if( index == GetSelectedIndex() )
	{
		bSelected = TRUE;
	}
	if(bSelected)
	{
		if( !m_bMoveItem )
		{
			if( m_width != ( pRect->right - pRect->left ) )
			{
				if( m_selectBgDC )
				{
					SelectObject( m_selectBgDC, m_hOldSelectBg );
					DeleteObject( m_hSelectBg );
					DeleteDC( m_selectBgDC );
					m_selectBgDC = NULL;
					m_hOldSelectBg = NULL;
					m_hSelectBg = NULL;
				}
				m_width = pRect->right - pRect->left;
			}
			if( m_selectBgDC == NULL )
			{
				m_selectBgDC = CreateCompatibleDC( hdc );
				m_hSelectBg = CreateCompatibleBitmap( hdc, pRect->right - pRect->left, pRect->bottom - pRect->top + 1 );
				m_hOldSelectBg = SelectObject( m_selectBgDC, m_hSelectBg );
				RECT rc = { 0, 0, pRect->right - pRect->left, pRect->bottom - pRect->top };
				MzDrawSelectedBg( m_selectBgDC, &rc );
			}
//jdhuang tmp shun
//			RECT rcTemp = {MAIN_LIST_X+m_RowIndex*DIR_LIST_ITEM_W,pRect->top,MAIN_LIST_X+(m_RowIndex+1)*DIR_LIST_ITEM_W,pRect->bottom};
			RECT rcTemp;
			//BitBlt( hdc, pRect->left, pRect->top, pRect->right - pRect->left, pRect->bottom - pRect->top + 1, m_selectBgDC, 0, 0, SRCCOPY );
			BitBlt( hdc, rcTemp.left, rcTemp.top, rcTemp.right - rcTemp.left, rcTemp.bottom - rcTemp.top + 1, m_selectBgDC, 0, 0, SRCCOPY );
			
		}
	}
}